package com.tencent.albert.weixin.driver.utils;

import com.tencent.albert.weixin.driver.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Neal on 2015/5/8.
 */
public class Report {

    private static Logger logger = LoggerFactory.getLogger(Report.class);

    /**
     * @desc sendAMessage
     */
    public static void send(
            String department,
            String name,
            String eventName,
            String eventStatus,
            String eventAttribute,
            String object1,
            String object2,
            String object3,
            String object4,
            String object5){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        headers.set("Content-Type", MediaType.APPLICATION_JSON + ";charset=UTF-8");

        try {
            String URL = Constants.REPORT_URL + department+"/"+name+"/"+object1+"/"+object2+"/"+object3+"/"+object4+"/"+object5+"/"+eventName+"/"+eventStatus+"/"+eventAttribute;
            restTemplate.getForObject(URL, String.class);
        }catch (Exception e) {
            logger.info("report error",e.getMessage());
        }
    }

    /**
     * report statistics data.
     * @param json
     */
    public static void send(String json){
        String url = "http://p.52xiaoluo.com/statistics/report/insert";
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        //headers.set("Content-Type", MediaType.APPLICATION_JSON + ";charset=UTF-8");

        restTemplate.postForObject(url + "?report={json}",null, String.class,json);
    }
}